package models;

import play.*;
import play.data.validation.Email;
import play.data.validation.Required;
import play.db.jpa.*;

import javax.persistence.*;

import net.sf.oval.constraint.DateRange;

import java.util.*;

@Entity
@Table(name="USERORDER")
public class Order extends BaseEntity {
	
	public enum OrderStatus {
		NEW, PAID, PAY_CONFIRM, SENDED, HISTORY, FAIL;
		//新订单、已付款、已确认付款、以发货、历史订单、废订单。
	}
	public OrderStatus orderStatus;
	
	//送货地址
	@Required
	public String deliveryAddress;
	//收货人
	@Required
	public String receiver;
	@Required
	public String phoneNo;
	@Email
	public String email;
	public String zipCode;
	//指定到达时间
	@Temporal(TemporalType.TIME)
	public Date arrivalTime;
	//指定物流公司
	public String orderTransportCompany;
	//用户的其他要求
	public String remark;
	//订货种类（自己订货、代发货）
	public String orderingType;
	public static final String ORDERTYPE_SELF="SELF";
	public static final String ORDERTYPE_AGENT="AGENT";
	
	//===========以下用于计算运费==============
	//-----------以下是当时的配置参数----------
	//起始运价不能超出的重量，超出的费用按每公斤递增。
	public double baseFreightKG;
	//起始运价。
	public double baseFreight;
	//每递增1公斤运费
	public double freightPerKG;
	//----------------------------------------
	//-----------以下通过计算出来的价格----------
	//货物总重量
	public double totalWeight;
	//总运价
	public double totalFreight;
	//商品总价格
	public double commodityPrice;
	//计算后的总价（commodityPrice+totalFreight）
	public double totalPrice;
	//----------------------------------------
	//===========以下用于计算运费==============
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
	public List<OrderItem> orderItems;
	
	/*标价对象*/
	@ManyToOne
	public User user;
	
	/*货物配送方式*/
	@ManyToOne
	@Required
	public TransferPrice transferPrice;
}
